﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using SY.Model;

namespace SY.DAL
{
    public class GoodsService
    {
        private DBHelper db = DBHelper.get();

        public List<GoodsInfo> GetDB(string code)
        {
            List<GoodsInfo> list = new List<GoodsInfo>();

            string sql = "select * from GoodsInfo where GoodsCode like '%" + code + "%'";

            DbDataReader dr = db.GetReader(sql);

            while (dr.Read())
            {
                GoodsInfo goods = new GoodsInfo();


                if (dr["Company"] != DBNull.Value)
                {
                    goods.Company = Convert.ToInt32(dr["Company"]);
                }


                goods.GoodsCode = dr["GoodsCode"].ToString();
                goods.GoodsName = dr["GoodsName"].ToString();
                goods.GoodsState = Convert.ToInt32(dr["GoodsState"]);
                goods.OriginPrice = Convert.ToDouble(dr["OriginPrice"]);
                goods.SalePrice = Convert.ToDouble(dr["SalePrice"]);


                if (dr["Stock"] != DBNull.Value)
                {
                    goods.Stock = Convert.ToInt32(dr["Stock"]);
                }
                if (dr["plier"] != DBNull.Value)
                {
                    goods.Supplier = Convert.ToInt32(dr["plier"]);
                }
                goods.Unit = dr["Unit"].ToString();
                list.Add(goods);
            } 

            dr.Close();
            db.Close();

            return list;
        }
    }
}
